<template>
  <div class="reportMistakeInfoAction el-card is-always-shadow el-card__body">
    <avue-crud
      ref="waitSubmitMainCrud"
      :option="option"
      :table-loading="listLoading"
      :data="tableData"
      :page.sync="page"
      :search.sync="searchForm"
      @search-change="handleFilter"
      @selection-change="selectionChange"
      @on-load="search">
      <template slot="menuRight">
        <el-button type="primary" size="mini" v-if="isRunningFlag" @click="submitHlwData()">提交</el-button>
<!--        <el-button type="primary" size="mini" @click="exportData">导出</el-button>-->
      </template>

      <template slot="searchMenu" slot-scope="{row,size}">
        <el-button :size="size" @click="()=>{setSearchFiledsEmpty(row);setSearchFiledsEmpty(searchForm)}" icon="el-icon-delete">清空</el-button>
      </template>
      <template slot-scope="scope" slot="menu">
        <el-button type="text" size="small" plain @click.stop="preview(scope.row)">预览</el-button>
      </template>
    </avue-crud>
<!--    <report-mistake-info-editor ref="reportMistakeInfoEditor" v-if="isShowReportMistakeInfoEditor"></report-mistake-info-editor>-->
    <preview ref="preview"></preview>
    <checkAccount ref="checkAccount" :params="{roleCode:'ZBZZ',isCheckRole:true}" @checkSubmitSuccess="checkSubmitSuccess"></checkAccount>

  </div>
</template>


<script>
    import {getForm, postForm} from '@/api/gen/gen'
    import ExportJsonExcel from "js-export-excel";
    import checkAccount from '../checkAccount.vue';
    import preview from './preview.vue';
    import moment from 'moment';
    import {
      getgetStationCodes,
      getLineCodes, getStationByCode, setSearchFiledsEmpty,getAutoSubmitFlag
    } from "../../../../api/subwayRat/commonCheck";
    import {exportDataToExcel} from "../../../../api/subwayRat/exportSelf";
    import {
      getXw_hlw_shouJieSuan_waitSubmit, hlwSubmitData,
      waitSubmitMainOptionList
    } from "../../../../api/stationTiecketManager/shouRuJieSuan/hlw/waitSubmitMain";
    export default {
      components:{preview,checkAccount
      },
      data() {
            return {
              row : {},
              listLoading: true,
              isRunningFlag: true,//表示是否正在自动提交
              fileTemp:{},
              searchForm:{},
              tableData:[],
              page: {
                total: 0, // 总页数
                currentPage: 1, // 当前页数
                pageSize: 20, // 每页显示多少条,
                isAsc: false// 是否倒序
              },
              autoWidth: true,
              downloadLoading: false,
              isShowReportMistakeInfoEditor:false,//是否加载编辑页面
              multipleSelectionRows:[],
              multipleSelectionKeys:[],
              lineCodes:[],
              stationCodes:[],
              reportNameIds:[],
              attendancePersonJobNo:null,//值班站长
              option:waitSubmitMainOptionList(),
            }
        },
        created() {
        },
        methods: {
          moment,setSearchFiledsEmpty,
          async exportData(){ // 导出
            this.searchForm.pageNo=1;
            this.searchForm.pageSize=1000000000;
            if(this.selectKeys.length>0){
              exportDataToExcel(this.selectKeys,this.option.column,'tvm结算-待提交主页');
            }else {
              let res=await getXw_hlw_shouJieSuan_waitSubmit(this.searchForm);
              let data = res.data.data;
              exportDataToExcel(data,this.option.column,'tvm结算-待提交主页');
            }
          },
          search(){

            Object.assign(this.searchForm,this.$refs.waitSubmitMainCrud?this.$refs.waitSubmitMainCrud.searchForm:{});
            Object.assign(this.searchForm,this.page);
            this.searchForm.approvalStatus=0;
            this.searchForm.lineCode=this.$store.getters.userInfo.lineCode;
            this.searchForm.stationCode=this.$store.getters.userInfo.stationCode;
            getXw_hlw_shouJieSuan_waitSubmit(this.searchForm).then((res)=>{
              this.tableData=res.data.data;
              this.listLoading = false;
              this.page.total=res.data.total;
            });
          },
          longZQJS(){
            this.$nextTick(()=>{
              this.$refs.longZQJS.dialogVisible=true;
              this.$refs.longZQJS.search();
            });
          },
          preview(row){
            this.$refs.preview.search(row);
          },
          submitHlwData(cab,callback){ //提交
            if(!this.attendancePersonJobNo){
              this.$message.warning("请值班站长登录确认后可提交");
              this.$refs.checkAccount.dialogVisibleAccountPassword=true;
              return;
            }
            if(this.multipleSelectionKeys.length<=0){
              this.$message.warning("请选择需要提交的数据");
              return;
            }
            hlwSubmitData({ids:this.multipleSelectionKeys.join(','),attendancePersonJobNo:this.attendancePersonJobNo}).then(res=>{
                cab(res)
                this.search();
                // if(res.data.code==0){
                //   this.$message.success("操作成功");
                //   this.search();
                //   return;
                // }else{
                //   this.$message.warning("操作失败");
                // }
            }).catch(error=> {
                callback(error)
                this.search();
            })
          },
          checkSubmitSuccess(res,cab,callback){
            this.attendancePersonJobNo=res;
            this.submitHlwData(cab,callback);
          },
          handleSelectionChange(val,a){
            this.multipleSelectionRows=val;
            this.multipleSelectionKeys=[];
            for(let i=0;i<this.multipleSelectionRows.length;i++){
              this.multipleSelectionKeys.push(this.multipleSelectionRows[i].id);
            }
          },
          initLine(){
            getLineCodes().then(res=>{ //获取线路
              this.lineCodes=res;
            });
          },
          initReportNameIds(){
            // getReports({}).then((res)=>{
            //   this.reportNameIds=res.data.data;
            // })
          },
          changeLine(v){
            getgetStationCodes(v).then(res=>{
              this.stationCodes=res;
            })
          },
          selectionChange(list){
            this.multipleSelectionRows=list;
            this.multipleSelectionKeys=[];
            for(let i=0;i<list.length;i++){
              this.multipleSelectionKeys.push(list[i].id);
            }
          },
          handleFilter(params, done) {
            Object.assign(this.searchForm,params);
            this.search()
            done()
          },
        },
      mounted() {
        this.search();
        this.initLine();
        this.initReportNameIds();

        //是否正在自动提交
        getAutoSubmitFlag({lineCode:this.$store.getters.userInfo.lineCode,stationCode:this.$store.getters.userInfo.stationCode}).then(res=>{
          if(res.data.code==0){
              if(res.data.data){
                let msg="系统正在自动提交，请勿进行操作！！！";             
                this.$message.warning(msg);
                this.listLoading = false;
                this.isRunningFlag = false;
            }
          }
        })
      }
    }
</script>
<style lang="scss">

</style>
